const s = {
  v: `
          attribute vec4 a_position;
          uniform mat4 mat_translation;
          void main() {
              gl_Position = mat_translation * a_position;
          }
      `,
  f: `
      precision mediump float;
      void main() {
          gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);
      }
      `,
}
// 得到着色器程序
const program = getProgram(gl, s)

// // 获取着色器程序中的变量
const a_position = gl.getAttribLocation(program, "a_position")
const mat_translation = gl.getUniformLocation(program, "mat_translation")
// //TODO 创建顶点数据

const data = new Float32Array([-0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5])
// // 创建缓冲对象
const buffer = gl.createBuffer()
// // 绑定缓冲对象
gl.bindBuffer(gl.ARRAY_BUFFER, buffer)
// // 填充缓冲对象
gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW)
// // 配置变量
gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 0, 0)
// // 启用变量
gl.enableVertexAttribArray(a_position)
let x = -1

// 动画循环
function animate() {
  x += 0.005
  if (x > 1) {
    x = -1
  }
  // gl.vertexAttrib1f(, i)
  const matrix = getTranslateMatrix(-x, -x)
  gl.uniformMatrix4fv(mat_translation, false, matrix)
  gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4)

  requestAnimationFrame(animate)
}
animate()
